package com.openbravo.pos.sales.restaurant;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import cn.ekuma.swing.dialog.AbstractKeyBoardJDialog;

import com.openbravo.bean.sales.KitchenWorkLine;
import com.openbravo.pos.sales.restaurant.kitchen.JKitchenLines;

public class JViewKitchenLineDialog extends AbstractKeyBoardJDialog {

	private final JPanel contentPanel = new JPanel();
	private JKitchenLines kitchenLines;
	
	 
    /**
     * @wbp.parser.constructor
     */
    public JViewKitchenLineDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
    }

    private  JViewKitchenLineDialog(java.awt.Dialog parent, boolean modal) {
        super(parent, modal);
    }
	

    public void loadData(List<KitchenWorkLine> lines){
    	kitchenLines.clearKitchenLines();
    	for(KitchenWorkLine l:lines)
    		kitchenLines.addKitchenLine(l);
    	setVisible(true);
	}
    
    public static JViewKitchenLineDialog newJDialog(Component parent,String lineColumnTxt){
        Window window = getWindow(parent);
        JViewKitchenLineDialog mydialog;
        if (window instanceof Frame) {
            mydialog = new JViewKitchenLineDialog((Frame) window, true);
        } else {
            mydialog = new JViewKitchenLineDialog((Dialog) window, true);
        }
        mydialog.init(lineColumnTxt);
        return mydialog;
    }
    

    private void init(String lineColumnTxt) {
    	initComponents();
		contentPanel.setLayout(new BorderLayout(0, 0));
		kitchenLines =new JKitchenLines(lineColumnTxt);
		contentPanel.add(kitchenLines);
		
	}
	
	private void initComponents(){
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
            
			JButton m_jButtonOK = new JButton();
				
				m_jButtonOK.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_ok.png"))); // NOI18N
		        m_jButtonOK.setFocusPainted(false);
		        m_jButtonOK.setFocusable(false);
		        m_jButtonOK.setMargin(new java.awt.Insets(8, 16, 8, 16));
		        m_jButtonOK.setRequestFocusEnabled(false);
		        m_jButtonOK.addActionListener(new java.awt.event.ActionListener() {
		            public void actionPerformed(java.awt.event.ActionEvent evt) {
		                m_jButtonOKActionPerformed(evt);
		            }
		        });
		        buttonPane.add(m_jButtonOK);
		      JButton m_jButtonCancel = new JButton();
		        m_jButtonCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_cancel.png"))); // NOI18N
		        m_jButtonCancel.setFocusPainted(false);
		        m_jButtonCancel.setFocusable(false);
		        m_jButtonCancel.setMargin(new java.awt.Insets(8, 16, 8, 16));
		        m_jButtonCancel.setRequestFocusEnabled(false);
		        m_jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
		            public void actionPerformed(java.awt.event.ActionEvent evt) {
		                m_jButtonCancelActionPerformed(evt);
		            }
		        });
				
				buttonPane.add(m_jButtonCancel);
				getRootPane().setDefaultButton(m_jButtonOK);
			
		}
	}

	protected void m_jButtonCancelActionPerformed(ActionEvent evt) {
		dispose();
	}

	protected void m_jButtonOKActionPerformed(ActionEvent evt) {
		dispose();
	}

	@Override
	protected void enterKeyProc() {
		dispose();
	}

	@Override
	protected void escapeKeyProc() {
		dispose();
	}

	@Override
	protected void upKeyProc() {
		kitchenLines.selectionUp();
	}

	@Override
	protected void downKeyProc() {
		kitchenLines.selectionDown();	
	}

}
